namespace lockfree
{
  template <typename T>
  class vector
  {
    public:
      vector() : data_(NULL),
                 size_(0),
                 pos_(0)
      {
      };
      ~vector()
      {
      };
    public:
      void resize(const int64_t size)
      {
        assert(NULL == data_);
        data_ = new T[size];
        size_ = size;
      };
      void push_back(const T &data)
      {
        int64_t pos = __sync_fetch_and_add(&pos_, 1);
        assert(pos < size_);
        data_[pos] = data;
      };
      T &operator[] (const int64_t index)
      {
        assert(index < size_);
        return data_[index];
      };
      int64_t size() const
      {
        return pos_;
      };
      void sort()
      {
        std::sort(data_, data_ + pos_);
      };
    public:
      T *data_;
      int64_t size_;
      volatile int64_t pos_;
  };
}
